﻿using System.IO;
using System.Text;
using System.Xml.Serialization;

namespace CoreComponents
{
    public class SerializationHelper<TRequest,TResponse>
    {
        public TRequest GetRequestObject(string request)
        {
            var serializer = new XmlSerializer(typeof(TRequest));

            using (var reader = new StringReader(request))
            {
                return (TRequest)serializer.Deserialize(reader);
            }
        }
        public string GetResponseString(TResponse response)
        {
            var result = new StringBuilder();
            var serializer = new XmlSerializer(typeof (TResponse));
            using (var writer = new StringWriter(result))
            {
                serializer.Serialize(writer,response);
            }
            return result.ToString();
        }
    }
}
